var searchRange = function(nums, target) {
    function getLeftBorder(nums,target){
        let left=0,right=nums.length-1
        let mid;
        let leftBorder=-2

        while(left<=right){
            mid=parseInt((left+right)/2)
            if(nums[mid]<target){
                left=mid+1
            }else{
                // right一直减，直到找到左边界
                right=mid-1
                leftBorder=mid
            }
        }

        return leftBorder
    }
    function getRightBorder(nums,target){
        let left=0,right=nums.length-1
        let mid;
        let rightBorder=-2

        while(left<=right){
            mid=parseInt((left+right)/2)
            if(nums[mid]>target){
                right=mid-1
            }else{
                // 
                left=mid+1
                rightBorder=mid
            }
        }

        return rightBorder
    }

    let leftBorder=getLeftBorder(nums,target)
    let rightBorder=getRightBorder(nums,target)
    console.log(leftBorder,rightBorder);

    // 找不到时肯定有一个是-2
    if(leftBorder==-2||rightBorder==-2) return [-1,-1]
    if(rightBorder-leftBorder>=0) return [leftBorder,rightBorder]
    return [-1,-1]
};